package com.lagou.order.controller;

import com.lagou.common.pojo.Goods;
import com.lagou.common.pojo.Order;
import com.lagou.order.feign.OrderFeign;
import com.lagou.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("order")
public class OrderController {

    @Value("${server.port}")
    private String port;

    @Autowired
    private OrderService orderService;

    @Autowired
    private OrderFeign orderFeign;

    /**
     * 根据订单id查询订单
     * @param id
     * @return
     */
    @GetMapping("getOrderById/{id}")
    public Order getOrderById(@PathVariable("id") String id){
        System.out.println("port = " + port);
        return orderService.geOrderById(id);
    }

    /**
     * 分页查询
     * pageSize = 10
     * 查询条件：订单创建时间范围、订单状态（未支付、已支付、已失效、已删除）
     * 返回类型：Map（list:订单集合、total:总条目数）
     * @param timeB
     * @param timeE
     * @param status
     * @param pageIndex
     * @param pageSize
     * @return
     */
    @GetMapping("getAllOrder")
    public Map<List<Order>, Integer> getAllOrder(String timeB, String timeE, Integer status, Integer pageIndex, Integer pageSize){
        System.out.println("port = " + port);
        return orderService.getAllOrder(timeB, timeE, status, pageIndex, pageSize);
    }

    /**
     * 根据订单id查询商品列表
     * @param id
     * @return
     */
    @GetMapping("getGoodsByOrderId/{id}")
    public Goods getGoodsByOrderId(@PathVariable("id") String id){
        System.out.println("port = " + port);
        Integer goodsId = orderService.getGoodsByOrderId(id);
        System.out.println("goodsId = " + goodsId);
        Goods goods = orderFeign.getGoodsById(goodsId);
        return goods;
    }

}
